<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var shopReturnDataGrid;
    $(function() {
        var statusArr = ['退货','审核通过','审核未通过','已退款'];

        shopReturnDataGrid = $('#shopReturnDataGrid').datagrid({
            url : '${path }/appShopReturn/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortShip : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                title : 'id',
                field : 'id',
                width : 40,
                hidden : true
            } ] ],
            columns : [ [ {
                field : 'returnNo',
                title : '退货单号',
                width : 200
            },{
                field : 'orderNo',
                title : '订单单号',
                width : 200
            },{
                field : 'goodsName',
                title : '商品名称 ',
                width : 180
            },{
                field : 'goodsTPrice',
                title : '商品总价',
                width : 80
            },{
                field : 'status',
                title : '状态',
                width : 100,
                formatter:function (value) {
                    return  statusArr[value];
                }
            } ,{
                field : 'createTime',
                title : '创建时间',
                width : 130
            },{
                field : 'action',
                title : '操作',
                width : 100,
                formatter : function(value, row, index) {
                    var str = '';
                    if(row.status==0){
                        <shiro:hasPermission name="/appShopReturn/edit">
                            str += $.formatString('<a href="javascript:void(0)" class="shopReturnDataGrid-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="auditReutn(\'{0}\');" >审核</a>', row.id);
                        </shiro:hasPermission>
                    }else{
                        str += $.formatString('<a href="javascript:void(0)" class="shopReturnDataGrid-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'"  >审核</a>', row.id);
                    }

                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.shopReturnDataGrid-easyui-linkbutton-return').linkbutton({text:'退款'});
                $('.shopReturnDataGrid-easyui-linkbutton-edit').linkbutton({text:'审核'});
            }
        });
    });

    /**
     * 退货审核
     * */
    function auditReutn(id) {
        if (id == undefined) {
            var rows = shopReturnDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            shopReturnDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '审核',
            width : 600,
            height : 400,
            href : '${path }/appShopReturn/editPage?id=' + id,
            buttons : [ {
                text : '通过',
                iconCls:'icon-ok',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = shopReturnDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#shopReturnAuditForm');
                    f.find('[name=status]').val(1);
                    f.submit();
                }
            } ,{
                text : '不通过',
                iconCls:'icon-del',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = shopReturnDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#shopReturnAuditForm');
                    f.find('[name=status]').val(2);
                    f.submit();
                }
            } ]
        });
    }

    function auditReutnMoney(id){
        if (id == undefined) {//点击右键菜单才会触发这个
            var rows = shopReturnDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {//点击操作里面的删除图标会触发这个
            shopReturnDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.messager.confirm('询问', '您是否要删除？', function(b) {
            if (b) {
                progressLoad();
                $.post('${path }/appService/delete', {
                    id : id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        shopReturnDataGrid.datagrid('reload');
                    }
                    progressClose();
                }, 'JSON');
            }
        });
    }




</script>
<div class="easyui-layout" data-options="fit:true,bShip:false">
    <div data-options="region:'center',fit:true,bShip:false">
        <table id="shopReturnDataGrid" data-options="fit:true,bShip:false"></table>
    </div>
</div>

</div>